package com.roberto.screens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
import com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.roberto.main.Main;

/**
 * The game over screen displays the final score and a game over text and waits for the user to touch the screen in which case it will signal that it
 * is done to the orchestrating GdxInvaders class.
 * 
 * @deprecated
 */
public class GameOver extends AbstractScreen {
	/** the SpriteBatch used to draw the background, logo and text **/
	private final SpriteBatch spriteBatch;
	/** the background texture **/
	private final Texture background;
	/** the logo texture **/
	private final Texture logo;
	/** the font **/
	private final BitmapFont font;
	/** is done flag **/
	private boolean isDone = false;
	/** 2d camera **/
	private OrthographicCamera camera;

	public GameOver() {
		spriteBatch = new SpriteBatch();
		camera = new OrthographicCamera();
		camera.setToOrtho(false, Main.WIDTH, Main.HEIGHT);
		background = new Texture(Gdx.files.internal("res/textures/background.png"));
		background.setFilter(TextureFilter.Linear, TextureFilter.Linear);

		logo = new Texture(Gdx.files.internal("res/menu/logo2.png"));
		logo.setFilter(TextureFilter.Linear, TextureFilter.Linear);

		font = new BitmapFont(Gdx.files.internal("res/arcade.fnt"), Gdx.files.internal("res/arcade.png"), false);
	}

	@Override
	public void dispose() {
		spriteBatch.dispose();
		background.dispose();
		logo.dispose();
		font.dispose();
	}

	@Override
	public boolean isDone() {
		return isDone;
	}

	@Override
	public void draw(float delta) {
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

		spriteBatch.setProjectionMatrix(camera.combined);
		spriteBatch.begin();
		spriteBatch.disableBlending();
		spriteBatch.setColor(Color.WHITE);
		spriteBatch.draw(background, 0, 0, Main.WIDTH, Main.HEIGHT);
		spriteBatch.enableBlending();
		spriteBatch.draw(logo, 300, Main.HEIGHT - 200);
		String text = "It is the end my friend.\nSpace to continue!";
		TextBounds bounds = font.getMultiLineBounds(text);
		spriteBatch.setBlendFunction(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA);
		font.drawMultiLine(spriteBatch, text, 270, 160 + bounds.height / 2, 480, HAlignment.CENTER);
		spriteBatch.end();
	}

	@Override
	public void update(float delta) {
		if (Gdx.input.isKeyPressed(Keys.SPACE)) {
			isDone = true;
		}
	}
}
